﻿Imports DataObject
Imports BusinessObject
Imports Microsoft.ApplicationBlocks.Data
Imports System.ComponentModel
Imports System.Reflection

Public Class frmHopDongLDList

    Private oHopDongLD As New BusHopDongLD
    Private oPrHopDongLD As New HopDongLD
    Private oConn As New hDBase
    Private ds As New DataSet
    Private cboNV As New Infragistics.Win.UltraWinGrid.UltraCombo
    Private cboSoViTriCV As New Infragistics.Win.UltraWinGrid.UltraCombo
    Private cboSoLoaiHDLD As New Infragistics.Win.UltraWinGrid.UltraCombo

    Private Sub frmHopDongLDList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitData()
        LoadGridView()
        RefreshToolbar()
        LoadAllCombo()
    End Sub

    Protected Overrides Sub LoadDataGrid()
        Try
            tableDictionary = oHopDongLD.GetAllHopDongLD(sConn)
            ListBindingSource.DataSource = tableDictionary
            grdList.DataSource = ListBindingSource
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub LoadGridView()
        Try
            grdList.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect
            With grdList.DisplayLayout.Bands(0)
                .Columns("SoHopDongLD").Hidden = True
                .Columns("TenHopDongLD").Hidden = True
                .Columns("NgayHetHieuLuc").Hidden = True
                .Columns("HinhThucLamViec").Hidden = True
                .Columns("MucLuongBaoHiem").Hidden = True
                .Columns("MucLuongThoaThuan").Hidden = True
                .Columns("PhuCap").Hidden = True
                .Columns("NguoiDaiDienKy").Hidden = True
                .Columns("ChucDanh").Hidden = True
                .Columns("DienGiai").Hidden = True
                .Columns("TepTinDinhKem").Hidden = True

                .Columns("MaHopDongLD").Header.Caption = "Số hợp đồng"
                .Columns("NgayKy").Header.Caption = "Ngày ký hợp đồng"
                .Columns("SoNV").Header.Caption = "Họ tên NLĐ"
                .Columns("SoViTriCV").Header.Caption = "Vị trí công việc"
                .Columns("SoLoaiHDLD").Header.Caption = "Loại hợp đồng"
                .Columns("NgayHieuLuc").Header.Caption = "Ngày hiệu lực"

                .Columns("NgayKy").Header.VisiblePosition = 1
                .Columns("MaHopDongLD").Header.VisiblePosition = 2
                .Columns("SoNV").Header.VisiblePosition = 3
                .Columns("SoViTriCV").Header.VisiblePosition = 4
                .Columns("SoLoaiHDLD").Header.VisiblePosition = 5
                .Columns("NgayHieuLuc").Header.VisiblePosition = 6
            End With
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub

    Protected Overrides Sub InitAddNewRow(ByVal oRow As System.Data.DataRow)
        With oRow
            .Item("MaHopDongLD") = ""
            .Item("TenHopDongLD") = ""
        End With
    End Sub

    Protected Overrides Function DeleteDictionary() As Boolean
        oPrHopDongLD.SoHopDongLD = iValue
        oHopDongLD.DeleteHopDongLD(sConn, oPrHopDongLD)
    End Function

    Private Sub grdList_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdList.MouseClick
        Try
            iValue = grdList.ActiveRow.Cells(TablePrimaryKey).Value
        Catch ex As Exception
        End Try
    End Sub

    Private Sub LoadAllCombo()
        ds.Clear()
        If (Not ds.Tables("NhanVien") Is Nothing) Then
            ds.Tables("NhanVien").Rows.Clear()
        End If
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Get_All_NhanViens", ds, New String() {"NhanVien"})
        With cboNV
            .DataSource = ds.Tables("NhanVien")
            .DisplayMember = "TenNV"
            .ValueMember = "SoNV"
        End With
        grdList.DisplayLayout.Bands(0).Columns("SoNV").EditorControl = cboNV
        grdList.DisplayLayout.Bands(0).Columns("SoNV").CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit

        If (Not ds.Tables("ViTriCongViec") Is Nothing) Then
            ds.Tables("ViTriCongViec").Rows.Clear()
        End If
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Get_All_ViTriCongViecs", ds, New String() {"ViTriCongViec"})
        With cboSoViTriCV
            .DataSource = ds.Tables("ViTriCongViec")
            .DisplayMember = "TenViTriCV"
            .ValueMember = "SoViTriCV"
        End With
        grdList.DisplayLayout.Bands(0).Columns("SoViTriCV").EditorControl = cboSoViTriCV
        grdList.DisplayLayout.Bands(0).Columns("SoViTriCV").CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit

        If (Not ds.Tables("LoaiHopDongLD") Is Nothing) Then
            ds.Tables("LoaiHopDongLD").Rows.Clear()
        End If
        SqlHelper.FillDataset(sConn, CommandType.StoredProcedure, "Get_All_LoaiHopDongLDs", ds, New String() {"LoaiHopDongLD"})
        With cboSoLoaiHDLD
            .DataSource = ds.Tables("LoaiHopDongLD")
            .DisplayMember = "TenLoaiHDLD"
            .ValueMember = "SoLoaiHDLD"
        End With
        grdList.DisplayLayout.Bands(0).Columns("SoLoaiHDLD").EditorControl = cboSoLoaiHDLD
        grdList.DisplayLayout.Bands(0).Columns("SoLoaiHDLD").CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit
    End Sub

 

End Class
